package com.example.asynctaskdemo.okhttp;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by kunge hu on 2016/11/1.
 */
public class GetTask extends AsyncTask<Void, Void, String> {

    private OjjlgHttpRequestCallBack listener;
    private String url;
    private Map<String, String> getmapparams;
    private String type;

    public GetTask(final String url, final String type, final Map<String, String> getmapparams,OjjlgHttpRequestCallBack listener) {
        this.url = url;
        this.listener = listener;
        this.getmapparams=getmapparams;
        this.type=type;
    }

    @SuppressLint("NewApi")
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    @Override
    protected String doInBackground(Void... params) {
        try {
            String geturl="";
            geturl=OjjlgRequestUtil.clwuyGetUrl(url,getmapparams);
            NbzgmNetWorkRequest request = new NbzgmNetWorkRequest();
            Map<String, String> headerMap=new HashMap<>();
            headerMap.put("x-method","post");
            headerMap.put("x-request",type);
            String contextType="application/json;charset=utf-8";
            NbzgmNetResponse response =request.qecrnNetWordRequst(geturl,"GET",contextType,"",headerMap);
            return  response.dkpdpResponseContent;
        } catch (Exception e) {
            Log.e("kunge.hu", "GetTask Exception:" + e.toString());
        }
        return null;
    }



    @SuppressLint("NewApi")
    @Override
    protected void onPostExecute(String t) {
        try {
            JSONObject jsonObject=new JSONObject(t);
            listener.clwuyHttpCallBackListener(t);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
